package com.example.gymmanagement.controller;

import com.example.gymmanagement.Utils.Result;
import com.example.gymmanagement.Utils.StatusCode;
import com.example.gymmanagement.domain.Field;
import com.example.gymmanagement.domain.Matchs;
import com.example.gymmanagement.domain.Notify;
import com.example.gymmanagement.service.NotifyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 *公告管理
 */
@RestController
@RequestMapping("/notify")
public class NotifyController {
    @Autowired
    private NotifyService notifyService;

    @PostMapping("/save")
    @ApiOperation("公告保存")
    public Result save(@RequestBody Notify notify,@RequestHeader("Authorization") String token){
        boolean flag = notifyService.insert(notify);
        String msg = flag?"添加公告成功":"添加公告失败";
        return new Result(flag? StatusCode.SAVE_OK:StatusCode.SAVE_ERR,notify,msg);
    }

    @ApiOperation("查询公告（分页）")
    @GetMapping("/listPage")
    public Result listPage(int index, int size, Notify notify,@RequestHeader("Authorization") String token){
        Result notifyList = this.notifyService.selectList(index,size,notify);
        return notifyList;
    }

    @ApiOperation("按id删除公告")
    @GetMapping("/deleteById")
    public Result deleteById(int id,@RequestHeader("Authorization") String token){
        boolean flag = notifyService.deleteById(id);
        String msg = flag?"删除公告成功":"删除公告失败";
        return new Result(flag? StatusCode.SAVE_OK:StatusCode.SAVE_ERR,"操作公告id为"+id,msg);
    }

    @ApiOperation("按id修改公告")
    @PostMapping("/updateNotify")
    public Result updateField(@RequestBody Notify notify, @RequestHeader("Authorization") String token){
        boolean flag = notifyService.updateField(notify);
        String msg = flag?"修改公告成功":"修改公告失败";
        return new Result(flag? StatusCode.UPDATE_OK:StatusCode.UPDATE_ERR,notify,msg);
    }
}
